package com.seal.yoyoshop.dao.impl;

import com.seal.yoyoshop.bin.Type;
import com.seal.yoyoshop.dao.TypeDao;
import com.seal.yoyoshop.util.DBUtils;

import java.util.List;

public class TypeDaoImpl implements TypeDao {
    @Override
    public Type selectTypeById(int id) {
        String sql = "SELECT * FROM type WHERE id = ? AND status = 1";
        Type type = DBUtils.queryOne(sql,Type.class,id);
        return type;
    }

    @Override
    public List<Type> selectTypeList() {
        String sql = "SELECT * FROM type WHERE status = 1";
        List<Type> typeList = DBUtils.query(sql,Type.class);
        return typeList;
    }

    @Override
    public boolean insertType(Type type) {
        String sql = "INSERT INTO type(name) VALUES(?)";
        int row = DBUtils.update(sql,type.getName());
        if(row == 1)return true;
        return false;
    }

    @Override
    public boolean updateType(Type type) {
        String sql = "UPDATE type SET name = ? ,status = ? WHERE id = ?";
        int row = DBUtils.update(sql,type.getName(),type.getStatus(),type.getId());
        if(row == 1)return true;
        return false;
    }

}
